//
//  Dictionary+Extension.swift
//  Library_y
//
//  Created by JC on 2023/6/6.
//

import Foundation

public extension Dictionary {
    
    /// 字典合并
    ///
    /// - Parameter arr: 字典数组
    func combine(_ dic: Dictionary) -> Dictionary {
        var currentDic = self
        for item in dic {
            currentDic[item.key] = dic[item.key]
        }
        return currentDic
    }
}

// MARK: 字典转字符串
public extension Dictionary {
    
    func toJsonString() -> String? {
        guard let data = try? JSONSerialization.data(withJSONObject: self, options: []) else { return nil }
        guard let str = String(data: data, encoding: .utf8) else { return nil }
        return str
     }
    
}
